<%
	form_name = form_filter_sort_by(@options[:scaffold_model])
%>
<%= start_form_tag @form_options, {:name => form_name, :id => form_name} %>
<% # is this hidden field even necessary anymore if we can pass it in via the action on Submit()?%>
<%= hidden_field_tag(:page, 1) %>
<thead>  
 <tr>
	<%#= debug @scaffold_model.sortable? %>
	<%= render(:partial => dry_template_location('list_header')) %>
	<th class="actions">
<%
			if @options[:scaffold_model].filterable? or @options[:scaffold_model].sortable?
%>
			<div>
<%
			end
			if @options[:scaffold_model].filterable?
				
				if !DryScaffoldEngine.config(:search_icon).nil? and DryScaffoldEngine.config(:search_icon)
%>
					<%= image_submit_tag(DryScaffoldEngine.config(:search_icon), 
									:id => "#{form_name}_search", 
									:value => "Search", 
									:name => "search", 
									:onmouseover => "javascript:swapImg(this.id,'#{image_path(DryScaffoldEngine.config(:search_icon_on))}')",
									:onmouseout => "javascript:swapImg(this.id,'#{image_path(DryScaffoldEngine.config(:search_icon))}')") %>
<%
				else
%>
					<%= submit_tag("Search", 
								:value => "Search", 
								:name => "search") %>
<%
				end
			end
%>
<%
			if @options[:scaffold_model].filterable? or @options[:scaffold_model].sortable?
				if @paging || @list_rows.size == 1 
					if !DryScaffoldEngine.config(:reset_icon).nil? and DryScaffoldEngine.config(:reset_icon)
				%>
					<%= image_submit_tag(DryScaffoldEngine.config(:reset_icon), 
								:id => "#{form_name}_reset", 
								:value => "Reset", 
								:name => "reset", 
								:onmouseover => "javascript:swapImg(this.id,'#{image_path(DryScaffoldEngine.config(:reset_icon_on))}')",
								:onmouseout => "javascript:swapImg(this.id,'#{image_path(DryScaffoldEngine.config(:reset_icon))}')") %>
				<%
					else
%>
					<%= submit_tag("Reset",
								:value => "Reset", 
								:name => "reset")%>
				<%
					end
				end
				%>
					<%= hidden_field_tag sort_limit_field_name(@options[:scaffold_model]), sort_limit(@options[:scaffold_model]) %>
			</div>
<% 
			end 
%>
	</th>
 </tr>
</thead>  
<tbody>
  <tr>
    <td colspan="<%= num_columns_in_list + 1 %>" class="messages-container">
      <div id="<%= scaffold_messages_id(@options) %>">
        <%= render :partial => 'shared/messages' %>
      </div>
      <p id="<%= empty_message_id(@options) %>" class="empty-message" <%= " style=\"display:none;\" " if !@list_rows.empty? %>>
        No Entries
      </p>      
    </td>
  </tr>
</tbody> 
<%= end_form_tag %>
<%	
	if not @list_rows.empty?
		@n_row = 0
		@edit_row = @one_row # Store what was validated
		for @one_row in @list_rows
			classAttr = cycle("", "class=\"even\"") 
			shown = false
 %>
		<tr <%=classAttr%>>
<%
			if @options[:scaffold_model].to_s == @one_row_options[:crud_model].to_s and 
					@one_row_options[:id].to_s == @one_row.id.to_s and 
					(@one_row_options[:crud_action] == "edit" or @one_row_options[:crud_action] == "show")%>
		  	<td colspan="<%= num_columns_in_list %>" class="<%= @one_row_options[:crud_action] %>">
		<%	case @one_row_options[:crud_action] 
					when "edit":
						if @scaffold_model.is_crudable?(:editable)
							shown = true 
							@one_row = @edit_row %>
						<%= render(:partial => 'shared/new_edit') %>
			<%	
						end
					when "show": 
						if @scaffold_model.is_crudable?(:showable)
							shown = true %>
						<%= render(:partial => 'shared/ro_show') %>
<% 	
						end
				end %>
				</td>
	<%	end 
			unless shown %>
				<%= render(:partial => dry_template_location('list_row'), :locals => {:one_row => @one_row}) %>
<%
			end
%>
			<td class="actions">
				<%= render(:partial => dry_template_location('actions'), :locals => {:one_row => @one_row}) %>
			</td>
		</tr>
<%
			@n_row += 1
		end 
	end
%>
